package com.gitee.cui.concurrency.designmodel.forkjoin;

import com.gitee.cui.util.Print;
import org.junit.Assert;
import org.junit.Test;

import java.util.concurrent.*;

/**
 * ForkJoin模式测试类
 * @author cuiqingqiang
 * @version 1.0
 * @date 2021/12/9 9:35
 **/
public class ForkJoinTest {

    @Test
    public void accumulateTaskTest() throws ExecutionException, InterruptedException, TimeoutException {
        ForkJoinPool forkJoinPool = new ForkJoinPool();
        AccumulateTask task = new AccumulateTask(1, 100);
        Future<Integer> future = forkJoinPool.submit(task);
        Integer sum = future.get(1, TimeUnit.SECONDS);
        Print.tcfo("最终的计算结果：" + sum);
        Assert.assertTrue(5050 == sum);
    }
}
